<?php
/**
 * Created by PhpStorm.
 * User: *!N.J
 * Date: 2021/8/22
 * Time: 4:25
 * QQ:1467572213
 */

namespace app\bx\controller;

use think\facade\Config;
use think\facade\Request;
use think\facade\Session;
use \app\bx\model\Recharge as Recharge_m;

class Recharge extends Base
{
    public function index()
    {
//        $redirectUrl  = Request::get();
//        $arr = json_decode($redirectUrl['body'],true);
        $recharge_api = Recharge_m::recharge_api();
        $this->assign('recharge_api',$recharge_api);
        return $this->fetch();
    }
    
     public function trc20(){
        $money = input('money');
        $user_id = Session::get('user_id');
        $user_info = \app\ch\model\Base::get_user_info($user_id);
        $data['id'] = $user_info['id'];
        $data['money'] = $money;
        $this->assign('data',$data);
        return $this->fetch();
    }
    
    public function erc20(){
        $money = input('money');
        $user_id = Session::get('user_id');
        $user_info = \app\ch\model\Base::get_user_info($user_id);
        $data['id'] = $user_info['id'];
        $data['money'] = $money;
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function recharge()
    {
        $user_id = Session::get('user_id');
        $user_info = \app\bx\model\Base::get_user_info($user_id);
        $start_recharge = \app\bx\model\Base::get_config($name = 'start_recharge');
        if (Request::isPost()){
            $money = Request::post('money');
            if ($money < $start_recharge) return ['code'=>0,'msg'=>'Minimum recharge:'.$start_recharge];
            $type = Request::post('type');
            switch ($type)
            {
                case 'shineupay':
                    $res = Recharge_m::shineupay($user_info,$money);
                    if ($res != 'error'){
                        return ['code'=>1,'data'=>$res];
                    }else{
                        return ['code'=>0,'msg'=>'System error, please contact customer service!'];
                    }
                    break;
                case 'Razorpay':
                    return ['code'=>0,'msg'=>'Not opened yet'];
                    break;
                case 'Oceanpay':
                    $res = Recharge_m::oceanpay($user_info,$money);
                    if ($res['code'] == 1){
                        return ['code'=>1,'data'=>$res['data']];
                    }else{
                        return ['code'=>0,'msg'=>'System error'];
                    }
                    break;
                case 'Global_pay':
                    $res = Recharge_m::Global_pay($user_info,$money);
                    return $res;
            }

        }
    }





}